package com.wzw.springboot.principle.use.security.infrastructure.point;

import com.wzw.springboot.principle.mvc.handler.ServletHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Serializable;

/**
 * 身份认证失败处理逻辑
 *
 * @author Wangzhiwen
 */
@Slf4j
@Component
public class UnAuthenticationEntryPoint implements AuthenticationEntryPoint, Serializable {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        ServletHandler.write(response, "用户身份认证失败");
    }
}
